﻿namespace KingerRobot.MexicoSailunWMS.SpiService
{
    internal class BLineManagerV2 : ILineManagerV2
    {
        public int InsertToScadaBoxTasks(ScadaBoxTaskParamV2 param)
        {
            var db = Db.Default;
            int result = db.ScadaBoxTaskss.Insert(new POScadaBoxTasks
            {
                TaskNo = param.TaskNo,
                Target = param.Target,
                Paint = param.Paint,
                Angle = param.Angle,
                OverTurn = param.OverTurn,
                Size = param.Size,
                LineCode = param.LineCode,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            });

            return result;
        }

        public POScadaBoxTasks QueryScadaBoxTasksByLineCode(string lineCode)
        {
            var db = Db.Default;
            var query = db.ScadaBoxTaskss.Where(f => f.LineCode == lineCode).FirstOrDefault();
            return query;
        }

        public int UpdateScadaBoxTasksByLineCode(ScadaBoxTaskParamV2 param)
        {
            var db = Db.Default;

            int result = db.ScadaBoxTaskss.Where(f => f.LineCode == param.LineCode).Update( new POScadaBoxTasks
            {
                TaskNo = param.TaskNo,
                Target = param.Target,
                Paint = param.Paint,
                Angle = param.Angle,
                OverTurn = param.OverTurn,
                Size = param.Size,
                UpdateTime = DateTime.Now
            });
            return result;
        }
    }
}
